package com.example.javabasic.shejimoshi.beiwanglu.demo2;

import com.example.javabasic.shejimoshi.beiwanglu.demo1.Originator;

//发起人
public class OriginatorPrototype implements Cloneable{
    //状态
    private String state;

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }
    //克隆一个发起人  返回
    public OriginatorPrototype createMemento(){
        //调用重写的clone()方法
        return this.clone();
    }
    //通过克隆对象 恢复状态
    public void restoreMemento(OriginatorPrototype originatorPrototype){
        this.setState(originatorPrototype.getState());
    }

    //重写克隆方法
    @Override
    public OriginatorPrototype clone(){
        try {
            //返回克隆内容
            return (OriginatorPrototype) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            System.out.println("克隆异常"+e.toString());
        }
        return null;
    }

}
